package LanQiaoDemo;

import java.util.Scanner;
import java.util.Stack;

public class Demo2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        String str = scan.next();
        boolean flag = method(str);
        System.out.println(flag ? 'Y' : 'N');
        scan.close();
    }

    private static <Satck> boolean method(String str) {
        int len = str.length();
        Stack<Character> stack = new Stack();
        for (int i = 0; i < len; i++) {
            char ch = str.charAt(i);
            if (ch == '(' || ch == '[' || ch == '{') {
                stack.push(ch);
            } else {
                char ch2 = stack.pop();
                if (!((ch2 == '(' && ch == ')') || (ch2 == '[' && ch == ']') || (ch2 == '{' && ch == '}'))) {
                    return false;
                }
            }
        }
        if (!stack.isEmpty()) {
            return false;
        }
        return true;
    }
}
